﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus
{
    public partial class tarifaForma : Form
    {
        private int idTarife;
        public tarifaForma()
        {
            InitializeComponent();
        }
        Tarifa tarifaObjekat = null;

        private void tarifaForma_Activated(object sender, EventArgs e)
        {
            tarifaObjekat = new Tarifa();
            tarifaObjekat.PopuniListBoxTarifa(listBoxTarife);
        }

        private void listBoxTarife_SelectedIndexChanged(object sender, EventArgs e)
        {
            idTarife=Convert.ToInt32(listBoxTarife.SelectedItem.ToString().Split('.')[0]);
            tarifaObjekat = new Tarifa();
            tarifaObjekat.PopuniKontroleNaOsnovuIdTarife(idTarife, textBoxOznaka, textBoxNaziv, textBoxSkracenica, textBoxStopa);
        }

        private void textBoxStopa_KeyPress(object sender, KeyPressEventArgs e)
        {
            Razno.DozvoliUnosSamoBrojevaIJedneTacke(sender, e);
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            tarifaObjekat = new Tarifa();
            tarifaObjekat.DodajTarifu(textBoxOznaka, textBoxNaziv, textBoxSkracenica, textBoxStopa);
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            tarifaObjekat = new Tarifa();
            tarifaObjekat.IzmeniTarifu(idTarife, textBoxOznaka, textBoxNaziv, textBoxSkracenica, textBoxStopa);
        }

        private void buttonObrisi_Click(object sender, EventArgs e)
        {
            tarifaObjekat = new Tarifa();
            tarifaObjekat.ObrisiTarifu(idTarife.ToString());
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxOznaka_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxSkracenica_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxStopa_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }

    }
}
